/*
 * TResizableFrame.h
 *
 *  Created on: 2011-12-1
 *      Author: Jeff
 */

#ifndef TResizableFrame_H_
#define TResizableFrame_H_
#include <QFrame>

class TResizableFrame
  : public QFrame
{
  Q_OBJECT

public:
  explicit TResizableFrame(QWidget *parent, Qt::WindowFlags f = 0);

  enum HitTestResult
  {
    HT_NONE,
    HT_LEFT,
    HT_TOP,
    HT_RIGHT,
    HT_BOTTOM,
    HT_LEFTTOP,
    HT_RIGHTTOP,
    HT_LEFTBOTTOM,
    HT_RIGHTBOTTOM,
  };

signals:
  void beginToResize();
  void resizeFinished();

public:
  bool isResizeEnabled() const
  {
    return _resizeEnabled;
  }
  void setResizeEnabled(bool setting);

  bool isResizing() const
  {
    return _resizeFrame != HT_NONE;
  }

  void setResizeWidth(int w)
  {
    _resizeWidth = w;
  }

  int hitTest(const QPoint& mpos) const;

protected:
  void mousePressEvent(QMouseEvent* e);
  void mouseReleaseEvent(QMouseEvent* e);

  bool eventFilter(QObject* obj, QEvent* e);

private:
  void changeCursor(int ht);
  void resizeFrame();

public:
  static QRect getScreenClipRect(QWidget* w);
  static bool isFixedSize(QWidget* w);

private:
  bool _resizeEnabled;
  int _resizeWidth;
  int _resizeFrame;
  QPoint _resizeStartPosition;
  int _lastHit;
};

#endif /* TResizableFrame_H_ */
